<template>
	<view class="my">
		<view class="my-bg"></view>
		<view class="my-avatar">
			<u-avatar :src="avatarUrl" size="200"></u-avatar>
			<view class="my-text">{{ nickName }}</view>
		</view>
		<view class="my-content">
			<view class="text-items">
				<infoItem :infoText="phoneNumber" :itemText="'手机号码'" :iconSrc="'../../static/phone.png'"></infoItem>
				<infoItem :itemText="'报价计算器'" :iconSrc="'../../static/calculator-select.png'" :calculator="true"></infoItem>
				<infoItem :itemText="'新手指引'" :iconSrc="'../../static/guide.png'" :guide="true"></infoItem>
				<infoItem :infoText="'132******52'" :itemText="'联系客服'" :iconSrc="'../../static/customer-phone.png'" :callPhoneNumber="true"></infoItem>
			</view>
		</view>
		<u-button type="success" @click="unLogin" size="medium" style="margin-top: 70%;">退出登录</u-button>
		<u-modal v-model="unLoginShow" content="确认退出登录吗？" :show-cancel-button="true" :mask-close-able="true" @confirm="sureLogin" @cancel="unLoginShow = false"></u-modal>
	</view>
</template>

<script>
	import store from '@/store/index.js'; //需要引入store
	import { mapState } from 'vuex' //引入mapState
	import infoItem from '../../../components/personal/infoItem'
	export default {
		onLoad() {
			var result = /^(\d{3})\d{6}(\d{2})$/;
			let loginForm = wx.getStorageSync('loginForm');
			this.phoneNumber = loginForm.username.toString().replace(result,"$1******$2");
			this.onShareAppMessage();
			this.onShareTimeline();
		},
		computed: {
			...mapState({
				nickName: state => state.user.nickName,
				avatarUrl: state => state.user.avatarUrl
			}),
		},
		data() {
			return{
				phoneNumber: '',
				unLoginShow: false
			}
		},
		components: {
			infoItem
		},
		methods: {
			unLogin() {
				this.unLoginShow = true;
			},
			sureLogin() {
				wx.removeStorageSync('user');
				wx.removeStorageSync('token');
				wx.removeStorageSync('draftQuotationData');
				wx.navigateTo({
					url: '../../login/login'
				})
			},
			onShareAppMessage() {
				const promise = new Promise(resolve => {
					setTimeout(() => {
						resolve({
							title: '鑫三元催化风向标'
						})
					}, 1000)
				})
				return {
					title: '鑫三元催化风向标',
					promise 
				}
			},
			onShareTimeline() {
				const promise = new Promise(resolve => {
					setTimeout(() => {
						resolve({
							title: '鑫三元催化风向标'
						})
					}, 1000)
				})
				return {
					title: '鑫三元催化风向标',
					promise 
				}
			}
		}
	}
</script>

<style>
	@import url("../../../common/css/my.css");
</style>
